(function(){
	@@include("./common/_menu.js")
	@@include("./common/_popWindow.js")
	$(".favorite-box").on("click",".favor",function(){
		if($(this).hasClass("hov")){
			$(this).removeClass("hov");
		}else{
			$(this).addClass("hov");
		}
	})
	$(".search-button").click(function(){
		if($(this).hasClass("hov")){
			$(this).removeClass("hov");
			$(this).next(".search-list").hide();
		}else{
			$(this).addClass("hov");
			$(this).next(".search-list").show();
		}	
	})
	$(".search-list li").click(function(){
		var val = $(this).html();
		$(".search-button span").eq(1).html(val);
		$(".search-button").removeClass("hov");
		$(this).parent(".search-list").hide();
	})
	//瀑布流
	$("img.lazy").lazyload({ 
        placeholder : "./images/images_4@2x.png",
        effect: "show",
        threshold :600
    });
	$(".infinite-scroll").infinitescroll({
		navSelector: ".recommend-more",
		nextSelector: ".recommend-more a",
		itemSelector: ".item",
		requestUrl: "./lib/recommend.json?type=home&categor_id=1&page=",	
		loading:{
			img: "images/masonry_loading_1.gif",
			msgText: ' ',
			finishedMsg: '',
			render: function(resData,opts){
				var data = "";
				try{
	                var temp = JSON.parse(resData);
	                if(temp.code == 200) {
	                    if(opts.state.currPage >= temp.data.last_page){
	                        opts.state.isFinished = true;
	                    }
	                    $.each(temp.data.data,function(i,item){
	                    	var price = item.current_price ? item.current_price : item.original_price;
	                    	data += '<div class="img-text item"><div class="img-text-left"><a href="'+item.href2+'"><span class="img-show"><img class="lazy" data-original="'+item.cover+'" alt=""></span></a></div><div class="img-text-right"><span class="favor hov"><i></i><em>Favorited</em></span><a href="1" class="descrption">'+item.name+' </a><div class="tips"><a href="'+item.href2+'" class="price">'+price+'</a><p><a>Best Primers for Oily Skin：<em>NO.'+item.ranking_rank+'</em></a></p></div><div class="introduce">'+item.intro+'</div></div></div>';
	                    })
	                }
	            }catch(e){}
	            return data;
			},
			finished: function(opts){
				if(opts.state.isFinished){ //结束事件
					$(".recommend-more").remove();
					$("#infscr-loading").hide();
					$(window).unbind('.infscr');
				}
			}	
		},errorCallback:function(res){ 
			console.log(res);
		}
		
	},function(newElements){
		var $newElems = $(newElements);
		$('.infinite-scroll').append($newElems);
		$newElems.fadeIn();
		//瀑布流
		$("img.lazy").lazyload({ 
	        placeholder : "./images/images_4@2x.png",
	        effect: "show",
	        threshold :600
	    });
		return;
	});
})()